Skip to content

fix(firecracker): make vsock field a pointer so omitempty drops it without vAccel#814

Open
naman79820 wants to merge 1 commit into
urunc-dev:mainfrom
naman79820:fix/firecracker-vsock-omitempty
Open

fix(firecracker): make vsock field a pointer so omitempty drops it without vAccel#814
naman79820 wants to merge 1 commit into
urunc-dev:mainfrom
naman79820:fix/firecracker-vsock-omitempty

Conversation

@naman79820

@naman79820 naman79820 commented Jul 10, 2026

Copy link
Copy Markdown

Description

Firecracker's JSON config is generated in BuildExecCmd. The vsock device field (FirecrackerConfig.VSock) was declared as a struct value but tagged json:"vsock,omitempty". In Go's encoding/json, omitempty has no effect on struct values (a struct is never considered empty), so the key was always emitted. As a result every non-vAccel Firecracker boot wrote a meaningless

vsock device into the config:

"vsock":{"guest_cid":0,"uds_path":"","vsock_id":""}

The code's intent is the opposite — the field is guarded by if args.VAccelType == "vsock" and tagged omitempty so the section should only appear when vAccel/vsock is in use. Guest CID 0 is reserved (valid CIDs start at 3) and the socket path is empty, so this is an invalid device entry.

This mirrors the same class of issue already fixed for the network-interfaces section in #310 (don't emit config that isn't needed).

Fix: make VSock a pointer (*FirecrackerVSockDev) so omitempty takes effect, and populate it only in the vAccel branch. A regression test asserts the generated config omits vsock without vAccel and includes it (with the configured guest CID) when vAccel is requested.

Related issues

How was this tested?

  • Added TestFirecrackerBuildExecCmdVSock (table test). Confirmed it fails on
    the current code (generated config contains the empty vsock device) and
    passes after the fix true red→green.
  • make unittest GO=$(which go) all unit packages pass.
  • gofmt -l cmd/ pkg/ internal/ clean; go vet ./pkg/unikontainers/hypervisors/ clean.
  • golangci-lint v2.9.0 on the changed package 0 issues.
  • go build ./... builds cleanly.

LLM usage

Claude Opus 4.8

Checklist

  • I have read the contribution guide.
  • The linter passes locally (ran golangci-lint v2.9.0 the version make lint uses; Docker was unavailable so I ran the binary directly).
  • The e2e tests of at least one tool pass locally (make test_ctr, make test_nerdctl, make test_docker, make test_crictl).
  • If LLMs were used: I have read the llm policy.

The vsock config field was a struct value rather than a pointer, so it was
always serialized into the generated Firecracker config even when vAccel was
not in use, producing a vsock device with a zero guest CID and an empty
socket path. Go's JSON encoder only drops empty pointers, slices and maps,
not zero-value structs.

Make the field a pointer and populate it only in the vAccel branch, so the
device is emitted solely when vsock-based vAccel is requested. Also add a
regression test asserting the config omits vsock without vAccel.

Fixes: #881
Signed-off-by: naman79820 <naman79820@gmail.com>
@netlify

netlify Bot commented Jul 10, 2026

Copy link
Copy Markdown

Deploy Preview for urunc canceled.

Name Link
🔨 Latest commit af15b3c
🔍 Latest deploy log https://app.netlify.com/projects/urunc/deploys/6a50abfe6f5c9400084d527a

@naman79820

Copy link
Copy Markdown
Author

@cmainas ready for review :))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Firecracker config always emits an empty vsock device (omitempty no-op on struct field)

1 participant